package com.liuyonggang.generator.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.liuyonggang.generator.dao.ProjectInfoMapper;
import com.liuyonggang.generator.model.ProjectInfo;
import com.liuyonggang.generator.util.PageInfo;
import com.liuyonggang.generator.util.ResultVo;

@Repository("projectInfoDal")
public class ProjectInfoDal {
	
	@Autowired
	private ProjectInfoMapper projectInfoMapper;

	public int countModel(){
		return projectInfoMapper.countModel();
	}

	public List<ProjectInfo> findAll(ProjectInfo task) {
		return projectInfoMapper.findAll(task);
	}

	public PageInfo<ProjectInfo> findAllByPage(PageInfo<ProjectInfo> pageInfo) {
	 	int count = projectInfoMapper.countByPage(pageInfo);
        PageInfo<ProjectInfo> page = new PageInfo<ProjectInfo>(count, pageInfo.getPageNumber(), pageInfo.getLimit());
        page.setList(projectInfoMapper.findAllByPage(pageInfo));
	    return page;
	}

    public ProjectInfo findById(Integer id) {
        ProjectInfo vo = null;
        try {
            vo = projectInfoMapper.findById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vo;
    }

    public ResultVo addProjectInfo(ProjectInfo projectInfo) {
        ResultVo vo = new ResultVo();
        try {
            projectInfoMapper.addProjectInfo(projectInfo);
        } catch (Exception e) {
            vo.setStatus(500);
            vo.setMessage("保存失败");
        }
        return vo;
    }

    public ResultVo updateProjectInfo(ProjectInfo projectInfo) {
        ResultVo vo = new ResultVo();
        try {
            projectInfoMapper.updateProjectInfo(projectInfo);
        } catch (Exception e) {
            vo.setStatus(500);
            vo.setMessage("保存失败");
        }
        return vo;
    }

    public ResultVo deleteProjectInfo(ProjectInfo projectInfo) {
        ResultVo vo = new ResultVo();
        try {
            projectInfoMapper.deleteProjectInfo(projectInfo);
        } catch (Exception e) {
            vo.setStatus(500);
            vo.setMessage("删除失败");
        }
        return vo;
    }
}
